package com.example.keli.ui.search;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.DensityUtil;
import com.example.keli.base.utils.GlideUtil;
import com.example.keli.base.utils.ScreenUtil;
import com.example.keli.base.utils.StringDesignUtil;
import com.example.keli.ui.my.model.InviteUserVO;

import java.util.List;

/**
 * description:
 * author: Allen
 * date: 2019/3/19 11:51
 */
public class SearchAdapter extends BaseQuickAdapter<SearchVO, BaseViewHolder> {

    private String mKeyValue = "";

    public SearchAdapter(List<SearchVO> mData, Context context) {
        super(R.layout.item_search, mData);
    }

    public void setKeyValue(String keyValue){
        this.mKeyValue = keyValue;
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchVO mListBean) {
        TextView name = helper.getView(R.id.tv_name);
        TextView city = helper.getView(R.id.tv_city);
        String name_str = mListBean.getNickname();
        String id_str = mListBean.getCode();
        String city_str = mListBean.getRegion_name();

        if (!TextUtils.isEmpty(name_str) && name_str.contains(mKeyValue)){
            city.setVisibility(View.GONE);
            name.setText(StringDesignUtil.getSpanned(name_str, mKeyValue, "#FFC12D"));
        }else if(!TextUtils.isEmpty(id_str) && id_str.contains(mKeyValue)){
            name.setText(name_str);
            city.setVisibility(View.VISIBLE);
            city.setText(StringDesignUtil.getSpanned(id_str, mKeyValue, "#FFC12D"));
        }else if(!TextUtils.isEmpty(city_str) && city_str.contains(mKeyValue)){
            name.setText(name_str);
            city.setVisibility(View.VISIBLE);
            city.setText(StringDesignUtil.getSpanned(city_str, mKeyValue, "#FFC12D"));//"地区:  "+
        }
        ImageView cover = helper.getView(R.id.iv_cover);
        GlideUtil.displayCircle(cover.getContext(), cover, mListBean.getAvatar());
    }

}
